package demo.practice.leetcode_msjd;

public class Msjd0107 {

    public static void main(String[] args) {
        int[][] arr= new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        new Msjd0107().rotate(arr);
    }
    public void rotate(int[][] matrix) {
        int len = matrix.length;
        int xmin = 0, ymin = 0;
        int xmax = len - 1, ymax = len - 1;
        while (xmin < xmax) {
            turn(matrix, xmin++, ymin++, xmax--, ymax--);
        }

    }


    private void turn(int[][] matrix, int xmin, int ymin, int xmax, int ymax) {
//        int L = matrix.length;
        int L= xmax-xmin;
        for (int i = 0; i < xmax-xmin; i++) {
            int tmp = matrix[xmin + i][ymin];
            matrix[xmin + i][ymin] = matrix[L-1-i][xmin + i];//
            matrix[L-1-i][xmin + i]=matrix[L-(xmin + i)][L-1-i];


//            matrix[ymin][ymax - (xmin + i)] = matrix[ymax - (xmin + i)][ymax - ymin];
//            matrix[ymax - (xmin + i)][ymax - ymin] = matrix[ymax - ymin][xmin + i];
//            matrix[ymax - ymin][xmin + i] = tmp;
        }
    }
}
